package linkedlist;



/**
 * 测试类
 */
public class Test {
    public static MySingleList.ListNode mergeTwoLists(MySingleList.ListNode head1, MySingleList.ListNode head2) {
        MySingleList.ListNode newHead = new MySingleList.ListNode(-1);
        MySingleList.ListNode tmpHead = newHead;
        while(head1 != null && head2 != null){
            if (head1.val < head2.val){
                tmpHead.next = head1;
                head1 = head1.next;
            }else{
                tmpHead.next = head2;
                head2 = head2.next;

            }
            tmpHead = tmpHead.next;

        }
        if(head1 != null){
            tmpHead.next = head1;
        }
        if(head2 != null){
            tmpHead.next = head2;
        }
        tmpHead = null;
        return newHead.next;

    }

    public static void main(String[] args) {
        MySingleList list = new MySingleList();
        list.addLast(1);
        list.addLast(3);
        list.addLast(5);
        list.addLast(7);
        list.addLast(9);
        list.display();
        System.out.println("=========");
        MySingleList list2 = new MySingleList();
        list2.addLast(2);
        list2.addLast(4);
        list2.addLast(6);
        list2.addLast(8);
        list2.addLast(10);
        list2.display();
//        MySingleList.ListNode listNode = mergeTwoLists(list.head, list2.head);
//        list.display();
        MySingleList list3 = new MySingleList();
        list3.addLast(1);
        list3.addLast(2);
        list3.addLast(3);
        list3.addLast(2);
        list3.addLast(1);
        list3.display();
        boolean isPal = list3.isPalindrome();
        System.out.println(isPal);


    }
    public static void main1(String[] args) {
        MySingleList list = new MySingleList();
        list.createList();
        System.out.println("====================");
        list.addFirst(1);
        list.addLast(99);
        list.remove(23);
        list.addLast(1);
        list.display();
        list.remove(56);
        list.remove(12);
        list.remove(34);
        list.display();
        //System.out.println(list.head.val);
        System.out.println("链表长度："+list.size());
        System.out.println(list.contains(67));
        System.out.println(list.contains(78));
        System.out.println("====================");
        MySingleList list2 = new MySingleList();
        list2.clear();
        list2.addIndex(0,1);
        list2.addIndex(1,1);
        list2.addIndex(2,1);
        list2.addIndex(3,1);
        list2.addIndex(4,1);
        list2.removeAllKey(1);
        list2.display();
        System.out.println("====================");
        MySingleList list3 = new MySingleList();
        list3.createList();
        list3.display();
        list3.reverseList();
        list3.display();
        MySingleList.ListNode listNode = list3.middleNode();
        System.out.println(listNode.val);




    }
}
